package com.xjtu.chapter08.thread.linkedblockingqueue;

import java.util.concurrent.BlockingQueue;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/9/1 10:41
 */
public class Producer implements Runnable {
    BlockingQueue<Product> queue;//利用阻塞队列存储

    public Producer(BlockingQueue<Product> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        try{
            Product item1 = new Product(1,"ipad");
            System.out.println("I have made a product: "+Thread.currentThread().getName());
            queue.put(item1);//放入产品
            System.out.println("I put in a product:"+item1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
